
package sat.component;

import org.mt4j.MTApplication;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.widgets.MTTextField;

import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragProcessor;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapProcessor;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;

public class KeyboardTextField extends MTTextField{

	private IGestureEventListener KeyboardListener;
	public IGestureEventListener getKeyboardListener() {
		return KeyboardListener;
	}

	public Keyboard keyboard;
	public enum type {nomral, classes, links, useCase};  //0 for normal, 1 for class,2 for link, 3 for user case
	public KeyboardTextField instance;
	public ClassComponentPopUp pp;

	//public boolean flagKB=true;

	public KeyboardTextField( final MTApplication mtApplication,float width, float height, final type keyBoardType,final ClassComponentPopUp ccppp,final UseCaseComponentPopUp uccp) {
		super(mtApplication, 0, 0, width, height, 
				FontManager.getInstance().createFont(mtApplication, "Comic Sans MS", 15, MTColor.BLACK));

		instance = this;

		//this.setEnableCaret(true);

		this.removeAllGestureEventListeners(DragProcessor.class);
		this.registerInputProcessor(new TapProcessor(mtApplication));
		this.KeyboardListener = new IGestureEventListener() {
			@Override
			public boolean processGestureEvent(MTGestureEvent ge) {
				// TODO Auto-generated method stub
				TapEvent te = (TapEvent)ge;
				switch (te.getTapID()) {
				case TapEvent.TAPPED:
					if(flagKeyboard)
					{
						instance.flagKeyboard=false;
						System.out.println("KeyBoard Text Field tapped");
						instance.setEnableCaret(true);
						keyboard = new Keyboard(mtApplication, keyBoardType, instance);
						keyboard.addTextInputListener(instance);
						keyboard.setVisible(true);
						instance.addChild(keyboard);
						mtApplication.getCurrentScene().getCanvas().addChild(keyboard);	
						if(ccppp!=null)
							ccppp.addKeyboard(keyboard);
						if(uccp!=null){
							keyboard.setPositionGlobal(new Vector3D(100,100));
							instance.addChild(keyboard);
						}
					}
					break;
				default:
					break;
				}
				return false;
			}

		};
		
		this.addGestureListener(TapProcessor.class, KeyboardListener);

	}





}
